package com.bj58.data.emailreports.sends;

import java.util.Date;
import java.util.List;

import com.bj58.data.emailreports.controllers.BusiMonthReportController;
import com.bj58.data.emailreports.model.EmailReportUser;
import com.bj58.data.emailreports.utils.DateUtil;

public class BMRSend extends BaseSend{

	public static void main(String[] args) {
		BMRSend  fs = new BMRSend();
		BusiMonthReportController  wk = new BusiMonthReportController();
		try {
			//执行日期   
			String searchDate = DateUtil.getStringDate(new Date(),"yyyy-MM-dd");
			
			//发送类型   all:part1-5  / 1:part1 / 2:part2 / 3:part3 / 4:part4 / 5:part5 
			String sendType = "all";
			
			if(null != args && args.length > 0){
				if(args.length != 2){
					System.out.println("params error ! ");
					System.exit(0);
				}
				
				if(args[0].contains("-")){
					searchDate = args[0].trim();
				}
				
				sendType = args[1].trim();
			}
			System.out.println(searchDate);
			System.out.println(sendType);
			
					
		//	String beginDate = DateUtil.getStringDate(DateUtil.getDateBefore(DateUtil.strToDate(searchDate, "yyyy-MM-dd"), 7),"yyyy-MM-dd");
		//	String endDate = DateUtil.getStringDate(DateUtil.getDateBefore(DateUtil.strToDate(searchDate, "yyyy-MM-dd"), 1),"yyyy-MM-dd");
			
		
			String beginDate = DateUtil.firstDayMonthBefore(searchDate, "yyyy-MM-dd",0);//查询日期（本月月第一天）
			String endDate = DateUtil.lastDayMonthBefore(searchDate, "yyyy-MM-dd",0);//查询日期（本月最后一天）
			
			System.out.println(" from " + beginDate + " to " + endDate);
			
			List<EmailReportUser> userListDayReport = fs.getUsersBySendType(36);//收件人
			
			
			String contextDayReport = "";

			//part 1
			if("all".equals(sendType.toLowerCase()) || "1".equals(sendType)){
				contextDayReport = wk.monthReportPartOne(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析月报 from "+ beginDate + " to " + endDate + " part-1");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析月报 from "+ beginDate + " to " + endDate + " part-1(总体进度/简历进度/收入趋势/流量趋势)", contextDayReport, null);
				}
			}
		
			
			//part 2
			if("all".equals(sendType.toLowerCase()) || "2".equals(sendType)){
				contextDayReport = wk.monthReportPartTwo(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析月报 from "+ beginDate + " to " + endDate + " part-2");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析月报 from "+ beginDate + " to " + endDate + "part-2(余额客户结构)" , contextDayReport, null);
				}
			}
			
			//part 3
			if("all".equals(sendType.toLowerCase()) || "3".equals(sendType)){
				contextDayReport = wk.monthReportPartThree(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析月报 from "+ beginDate + " to " + endDate + " part-3");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析月报 from "+ beginDate + " to " + endDate + "part-3(消耗周期)" , contextDayReport, null);
				}
			}
			
			//part 4
			if("all".equals(sendType.toLowerCase()) || "4".equals(sendType)){
				contextDayReport = wk.monthReportPartFour(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析月报 from "+ beginDate + " to " + endDate + " part-4");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析月报 from "+ beginDate + " to " + endDate + "part-4(自然流量数据/供求分析/在线产品收入对比)" , contextDayReport, null);
				}
			}
		
			//part 5
			if("all".equals(sendType.toLowerCase()) || "5".equals(sendType)){
				contextDayReport = wk.monthReportPartFive(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析月报 from "+ beginDate + " to " + endDate + " part-5");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析月报 from "+ beginDate + " to " + endDate + "part-5(城市监控/类别监控/分平台收入变化/分来源收入变化/新增流失客户)" , contextDayReport, null);
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
			fs.errorWarn("商业数据分析月报报错!");
		}finally{
			System.exit(0);
		}
	}
	
}
